import { DashLine } from 'pixi-dashed-line';
import * as PIXI from 'pixi.js';

/**
 * 虚线矩形框，在pixi-dashed-line基础上封装
 *
 * @export
 * @class DashedRectangle
 */
export default class DashedRectangle {
  constructor(obj) {
    this.obj = obj;
  }

  /**
   * 在obj上加一个虚线框的描边
   *
   * @return {*}
   * @memberof DashedRectangle
   */
  create() {
    const rect = this.obj.getBounds();
    const { x, y, width, height } = rect;
    const line = new PIXI.Graphics();
    const dash = new DashLine(line, {
      dash: [4, 3],
      width: 2,
      color: 0xffffff,
    });
    dash.moveTo(x, y);
    dash.lineTo(x + width, y);
    dash.lineTo(x + width, y + height);
    dash.lineTo(x, y + height);
    dash.lineTo(x, y);
    line.name = 'dashline';
    return line;
  }
}
